//
//  BaseViewController.swift
//  weibo
//
//  Created by mac on 15/12/14.
//  Copyright © 2015年 rong. All rights reserved.
//

import UIKit
//根据用户是否登录 去显示访客视图 还是表视图
class BaseViewController: UITableViewController,VisitorLoginViewDelegate{
    //设置用户是否登录的标记
    var userLogin = UserAccountViewModel().userLogin
    //新建属性访客视图
    var visitorLoginView: VisitorLoginView?
    override func loadView() {
        if userLogin {
        //显示tableView
            super.loadView()
        }else {
        setVisitorLoginView()
        }
    }
    private func setVisitorLoginView() {
    visitorLoginView = VisitorLoginView()
        //设置代理
        visitorLoginView?.visitroViewDelegate = self
        view = visitorLoginView
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "userWillLogin")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "userWillRegister")
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        print(view.bounds)
    }
    func userWillLogin() {
         print(__FUNCTION__)
        let oauth = OAuthViewController()
        //添加到 导航视图控制器
        let nav = UINavigationController(rootViewController: oauth)
        presentViewController(nav, animated: true, completion: nil)
    }
    func userWillRegister() {
        print(__FUNCTION__)
    }
}

